<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/10/26
  Time: 14:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.js"></script>
<script type="text/javascript">
      $(function(){
        $("#all").click(function () {
            $("input[name=ids]").prop("checked",$("#all").prop("checked"));
        });

        $("#btdel").click(function(){
          /* $("input[name=ids]:checked").each(function(obj){
                alert($(obj).val());
           });*/
          //定义js的数组
          var ids=[];//要删除的userid
          var datas=$("input[name=ids]:checked");
            for(var i=0;i<datas.length;i++){
                //console.info($(datas[i]).val());
                ids.push($(datas[i]).val())
            }
            //console.info(ids);[12,23]
            //将这ids传给控制器,
            var str=ids.join(",");//
            window.location.href="/user/deletes?ids="+ids;
        });
      });
</script>
<body>

    <form action="/user/pageList" method="post" id="queryForm">
        姓名:<input type="text" name="name" value="${user.name}"/>
        <input type="hidden" name="page" value="1" id="page"/>
        <input type="submit" value="查询"/>
    </form>
    <button id="btdel">批量删除</button>
    <table width="700" border="1">
        <tr>
            <th><input type="checkbox" id="all">全选</th><th>编号</th>  <th>姓名</th>  <th>年龄</th>  <th>地址</th><th>操作</th>
        </tr>
        <c:forEach items="${pageInfo.list}" var="user">
            <tr>
                <td><input type="checkbox" name="ids" value="${user.id}"/> </td>
                <td>${user.id}</td><td>${user.name}</td><td>${user.age}</td><td>${user.addr}</td>
                <td><a href="/user/delete/${user.id}">删除</a></td>
            </tr>
        </c:forEach>
    </table>
    <a href="javascript:goPage(1)">首页</a>
    <a href="javascript:goPage(${pageInfo.pageNum+1})">下一页</a>
    <a href="javascript:goPage(${pageInfo.pageNum-1})">上一页</a>
    <a href="javascript:goPage(${pageInfo.pages})">最后页</a>
     总记录数:${pageInfo.total} 总页面数:${pageInfo.pages} 当前页面:${pageInfo.pageNum}

    <script type="text/javascript">
        function goPage(num){
            document.getElementById("page").value=num;
            document.getElementById("queryForm").submit();
        }
    </script>
</body>
</html>
